package cn.lhf.cd.domain;

import cn.lhf.cd.entity.Order;
import javafx.beans.property.*;

import java.text.SimpleDateFormat;
import java.util.Objects;

public class OrderModel {
    private IntegerProperty serialNum;  //序号
    private LongProperty id;            //编号
    private StringProperty name;        //名字
    private StringProperty date;        //时间

    private static int nextSerialNum = 1;

    public OrderModel(Order order) {
        this.serialNum = new SimpleIntegerProperty(nextSerialNum ++);
        this.id = new SimpleLongProperty(order.getId());
        this.name = new SimpleStringProperty(order.getName());
        this.date = new SimpleStringProperty(new SimpleDateFormat("yyyy年MM月dd日").format(order.getDate()));
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof OrderModel)) return false;
        OrderModel model = (OrderModel) o;
        return Objects.equals(getId(), model.getId());
    }

    @Override
    public int hashCode() {
        return Objects.hash(getId());
    }

    public int getSerialNum() {
        return serialNum.get();
    }

    public IntegerProperty serialNumProperty() {
        return serialNum;
    }

    public void setSerialNum(int serialNum) {
        this.serialNum.set(serialNum);
    }

    public long getId() {
        return id.get();
    }

    public LongProperty idProperty() {
        return id;
    }

    public void setId(long id) {
        this.id.set(id);
    }

    public String getName() {
        return name.get();
    }

    public StringProperty nameProperty() {
        return name;
    }

    public void setName(String name) {
        this.name.set(name);
    }

    public String getDate() {
        return date.get();
    }

    public StringProperty dateProperty() {
        return date;
    }

    public void setDate(String date) {
        this.date.set(date);
    }
}
